package com.fqy.service.serviceImpl;

import com.aliyuncs.exceptions.ClientException;
import com.fqy.service.MemberService;
import com.fqy.util.AliyunSmsUtils;
import com.fqy.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author 风清扬
 * @version 1.0
 * @date 2021/7/4 16:02
 */
@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private AliyunSmsUtils aliyunSmsUtils;

    @Autowired
    private RedisServiceImpl redisService;

    /**
     * 获取验证码
     *
     * @param telephone
     * @return
     */
    @Override
    public CommonResult generateAuthCode(String telephone) throws ClientException {
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            sb.append(random.nextInt(10));
        }
//        AliyunSmsUtils.sendSms(telephone,sb.toString());
        redisService.set(telephone,sb.toString());
        return CommonResult.success(sb.toString(),"获取验证码成功");
    }

    /**
     * 判断验证码是否正确
     *
     * @param telephone
     * @param authCode
     * @return
     */
    @Override
    public CommonResult verifyAuthCode(String telephone, String authCode) {
        return null;
    }
}
